package com.jcp.baselibrary.base;

import android.os.Handler;
import android.support.multidex.MultiDexApplication;

import com.jcp.baselibrary.utils.FileUtil;
import com.jcp.baselibrary.utils.MyLogger;

import java.io.File;

/**
 * =========================================================
 * @ProjectName: 
 * @ClassName: BaseApplication
 * @Description: 
 * @Author: jincp
 * @CreateDate: 2019/3/14 20:07
 * =========================================================
 */
public class BaseApplication extends MultiDexApplication {

    protected static String TAG;

    //以下属性应用于整个应用程序，合理利用资源，减少资源浪费
    private static BaseApplication nInstance;//上下文
    private static Thread mMainThread;//主线程
    private static long mMainThreadId;//主线程id
    private static Handler mMainHandler;//主线程Handler

    private static File appCacheDir;

    public static File getAppCacheDir() {
        return appCacheDir;
    }


    @Override
    public void onCreate() {
        super.onCreate();
        TAG = getClass().getSimpleName();
        //对全局属性赋值
        nInstance = this;

        mMainThread = Thread.currentThread();
        mMainThreadId = android.os.Process.myTid();
        mMainHandler = new Handler(getMainLooper());

        appCacheDir = FileUtil.getAppCacheFile(this);
        MyLogger.d(TAG, "path : " + appCacheDir.getAbsolutePath());
    }

    public static BaseApplication getInstance() {
        return nInstance;
    }

    public static Thread getMainThread() {
        return mMainThread;
    }

    public static long getMainThreadId() {
        return mMainThreadId;
    }

    public static Handler getMainHandler() {
        return mMainHandler;
    }
}
